import { axios2 } from '@/utils/request'
// 用于返回文件夹下所有内容
const api = {
    file: '/file',
    department: '/department'
}

const baseUrl = 'http://localhost:8080'
// 文件夹内容浏览
export function getDocument (dirUrl) {
    return axios2.get(`${baseUrl}/list?dirUrl=${dirUrl}`)
}
// 用于创建新的文件夹
export function createMkdir (dirUrl) {
    return axios2.post(`${baseUrl}/file/mkdir?dirUrl=${dirUrl}`)
}
// 用于上传文件
export function uploadDocument (imgUrl) {
    return axios2.post(`${api.file}/upload?imgUrl${imgUrl}`)
}
// 用于下载文件
export function downloadDocument (url) {
    return axios2.post(`${api.file}/download?url=${url}`)
}
// 删除文件
export function deleteDocument (url) {
    return axios2.delete(`${api.file}/delete?url=${url}`)
}
// 用于获取机构信息
export function getDepartment (key) {
    return axios2.get(`${api.department}/list?key=${key}`)
}
// 用于新增机构
export function addDepartment (departmentName, departmentChar) {
    return axios2.post(`${api.department}/add?departmentName${departmentName}&departmentChar=${departmentChar}`)
}
// 用于更新机构信息
export function updateDepartment (newName, newChar, dId) {
    return axios2.put(`${api.department}/update?newName=${newName}&newChar=${newChar}&departmentId=${dId}`)
}
// 用于删除已有机构
export function deleteDepartment (dId) {
    return axios2.delete(`${api.department}/delete?dId=${dId}`)
}
export default {
    getDocument, createMkdir, uploadDocument, downloadDocument, deleteDocument, getDepartment, addDepartment, updateDepartment, deleteDepartment
}
